/*
 * Copyright (C) 2006 Erik Swenson - erik@oreports.com
 * 
 * This program is free software; you can redistribute it and/or modify it under the terms of the
 * GNU General Public License as published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with this program; if
 * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 */

package org.efs.openreports.engine.output;

import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import org.efs.openreports.util.ORUtil;
import org.efs.openreports.util.Releasable;

/**
 * This object contains the report content generated by the ReportEngine as a btye[] along with
 * additional information decribing the content
 * 
 * @author Erik Swenson
 */

public class ReportEngineOutput implements Serializable, Releasable {
    private static final long serialVersionUID = -1891016289500829002L;

    public static final String CONTENT_TYPE_PDF = "application/pdf";
    public static final String CONTENT_TYPE_XLS = "application/vnd.ms-excel";
    public static final String CONTENT_TYPE_HTML = "text/html";
    public static final String CONTENT_TYPE_CSV = "text/comma-separated-values";
    public static final String CONTENT_TYPE_RTF = "application/rtf";
    public static final String CONTENT_TYPE_TEXT = "text/plain";
    public static final String CONTENT_TYPE_XML = "application/xml";
    public static final String CONTENT_TYPE_JPEG = "image/jpeg";
    public static final String CONTENT_TYPE_PNG = "image/png";
    public static final String CONTENT_TYPE_XLSX = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
    private String contentType;
    private String contentMessage;
    // private byte[] content;
    private ContentManager contentManager = new ContentManager();

    private Map<String, Object> supplementaryContent = new HashMap<String, Object>();
    
    public ReportEngineOutput() {
        
    }

    /**
     * Provides supplementary content in a map.
     * 
     * @return
     */
    public Map<String, Object> getSupplementaryContent() {
        return supplementaryContent;
    }

    public byte[] getContentAsBytes() {
        return contentManager.getContentAsBytes();
    }

    /**
     * 
     * @param content clients should write to the the content managers output stream
     */
    public void setContent( byte[] content ) {
        this.contentManager.setContent( content );
    }

    public String getContentType() {
        return contentType;
    }

    public void setContentType( String contentType ) {
        this.contentType = contentType;
    }

    public String getContentMessage() {
        return contentMessage;
    }

    public void setContentMessage( String contentMessage ) {
        this.contentMessage = contentMessage;
    }

    public void setContentExtension( String contentExtension ) {
        // empty setter
    }

    public String getContentExtension() {
        return ORUtil.getContentExtension( this.contentType );
    }

    public void release() {
        contentManager.release();
    }

    public InputStream getContentStream() throws IOException {
        return contentManager.createInputStream();
    }

    public ContentManager getContentManager() {
        return contentManager;
    }
}
